﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.EquipmentManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.EquipmentManagement.EquipmentVMs
{
    public partial class EquipmentListVM : BasePagedListVM<Equipment_View, EquipmentSearcher>
    {
        
        protected override IEnumerable<IGridColumn<Equipment_View>> InitGridHeader()
        {
            return new List<GridColumn<Equipment_View>>{
                
                this.MakeGridHeader(x => x.Equipment_EquipName).SetTitle(@Localizer["Page.设备名称"].Value),
                this.MakeGridHeader(x => x.Equipment_EquipCode).SetTitle(@Localizer["Page.设备编号"].Value),
                this.MakeGridHeader(x => x.Equipment_EquipType).SetTitle(@Localizer["Page.设备类型"].Value),
                this.MakeGridHeader(x => x.Equipment_SpotType).SetTitle(@Localizer["Page.点检模式"].Value),
                this.MakeGridHeader(x => x.Equipment_DriverType).SetTitle(@Localizer["Page.驱动类型"].Value),
                this.MakeGridHeader(x => x.Equipment_IpAddress).SetTitle(@Localizer["Page.网络地址"].Value),
                this.MakeGridHeader(x => x.Equipment_Port).SetTitle(@Localizer["Page.端口"].Value),
                this.MakeGridHeader(x => x.Equipment_Actvie).SetTitle(@Localizer["Page.激活"].Value),
                this.MakeGridHeader(x => x.Equipment_Manufactor).SetTitle(@Localizer["Page.生产厂家"].Value),
                this.MakeGridHeader(x => x.Equipment_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.Equipment_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.Equipment_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.Equipment_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<Equipment_View> GetSearchQuery()
        {
            var query = DC.Set<Equipment>()
                
                .CheckContain(Searcher.EquipName, x=>x.EquipName)
                .CheckContain(Searcher.EquipCode, x=>x.EquipCode)
                .CheckEqual(Searcher.EquipType, x=>x.EquipType)
                .CheckEqual(Searcher.SpotType, x=>x.SpotType)
                .CheckEqual(Searcher.DriverType, x=>x.DriverType)
                .CheckContain(Searcher.IpAddress, x=>x.IpAddress)
                .CheckEqual(Searcher.Port, x=>x.Port)
                .CheckEqual(Searcher.Actvie, x=>x.Actvie)
                .CheckContain(Searcher.Manufactor, x=>x.Manufactor)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new Equipment_View
                {
				    ID = x.ID,
                    
                    Equipment_EquipName = x.EquipName,
                    Equipment_EquipCode = x.EquipCode,
                    Equipment_EquipType = x.EquipType,
                    Equipment_SpotType = x.SpotType,
                    Equipment_DriverType = x.DriverType,
                    Equipment_IpAddress = x.IpAddress,
                    Equipment_Port = x.Port,
                    Equipment_Actvie = x.Actvie,
                    Equipment_Manufactor = x.Manufactor,
                    Equipment_CreateTime = x.CreateTime,
                    Equipment_UpdateTime = x.UpdateTime,
                    Equipment_CreateBy = x.CreateBy,
                    Equipment_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class Equipment_View: Equipment
    {
        
        public string Equipment_EquipName { get; set; }
        public string Equipment_EquipCode { get; set; }
        public EquipTypeEnum? Equipment_EquipType { get; set; }
        public EquipSpotCheckEnum? Equipment_SpotType { get; set; }
        public DriverTypeEnum? Equipment_DriverType { get; set; }
        public string Equipment_IpAddress { get; set; }
        public int Equipment_Port { get; set; }
        public bool? Equipment_Actvie { get; set; }
        public string Equipment_Manufactor { get; set; }
        public DateTime? Equipment_CreateTime { get; set; }
        public DateTime? Equipment_UpdateTime { get; set; }
        public string Equipment_CreateBy { get; set; }
        public string Equipment_UpdateBy { get; set; }

    }

}